<?php
namespace Profile\Controller;
use Profile\Controller\BaseController;
class ProfileController extends BaseController {
	private $tbl;
	public function _initialize(){
		$this->tbl='users';
		$this->model=D($this->tbl);
		parent::_initialize();
	}
    public function index(){
		var_dump($this->tbl);
		parent::mod($this->tbl,"yjl_id");
    }
	public function update(){//修改
		parent::update($this->tbl,"yjl_photo");
		$this->redirect('Index');
	}
	public function mygroups(){
		$stunum=I('get.stunum');//获取id
		if($stunum==null){
			$stunum=$_SESSION['user']['yjl_stunum'];
		}
		
		// 创建的社团(通过审核)
		$data1=M("groups")->where("yjl_leader='{$stunum}' and yjl_check=1")->select();
		//var_dump($data1);exit;
		$this->assign("secblock1",$data1);
		
		// 创建社团（未通过审核）
		$data1=M("groups")->where("yjl_leader='{$stunum}' and yjl_check=0")->select();
		$this->assign("secblock2",$data1);
		
		//参加的社团(已审核)
		$sql="select * from yjl_groups where yjl_id in (
		select yjl_gid from yjl_members where yjl_stunum='{$stunum}' and yjl_check=1) and yjl_check=1";
		//echo $sql;exit;
		$data2=M()->query($sql);
		$this->assign("thirblock1",$data2);
		
		//参加的社团（未审核）
		$sql="select * from yjl_groups where yjl_id in (
		select yjl_gid from yjl_members where yjl_stunum='{$stunum}' and yjl_check=0)";
		//echo $sql;exit;
		$data2=M()->query($sql);
		$this->assign("thirblock2",$data2);
	
		
		$this->display();
	}
	public function mypractices(){		
		$stunum=I('get.stunum');//获取学号
		if($stunum==null){
			$stunum=$_SESSION['user']['yjl_stunum'];
		}
		//参加的活动未审核
		$sql="select * from yjl_practices where yjl_id in (
		select yjl_pid from yjl_stuprac where yjl_stunum='{$stunum}' and yjl_check=0)";
		//echo $sql;exit;
		$data3=M()->query($sql);
		$this->assign("forblock1",$data3);
		//var_dump($data3);
		//参加的活动已审核
		$sql="select * from yjl_practices where yjl_id in (
		select yjl_pid from yjl_stuprac where yjl_stunum='{$stunum}' and yjl_check=1)";
		
		$data3=M()->query($sql);
		//var_dump($data3);
		$this->assign("forblock2",$data3);
		
		$this->display();
	}
	public function formpwd(){
		$this->display();
	}
	public function modpwd(){
		$data=I('post.');
		//var_dump($data);
		if(md5($data['oldpass'])==$_SESSION['user']['yjl_pass']){
			$usermsg=array(
				'yjl_id'=>$_SESSION['user']['yjl_id'],
				'yjl_pass'=>md5($data['newpass'])
			);
			//var_dump($usermsg);
			$model=M("users");
			$res=$model->create($usermsg);
			if($res){
				$model->save();
				$_SESSION['user']['yjl_pass']=md5($data['newpass']);
				$this->success('修改成功！',U('formpwd'));
			}else{
				$this->error('修改失败！',U('formpwd'));
			}
		}else{
			$this->error('密码输入错误！！',U('formpwd'));
		}
	}
	public function leaderspace(){
		$this->display();
	}
}